// SEE END OF FILE FOR LICENSE TERMS

#include "p30f6010A.h"
#include "interface_defines.h"
#include "defines.h"

//	Variables.

unsigned int rise[MAX_INPUTS+1] ;	// rising edge clock capture for radio inputs
int pwIn[MAX_INPUTS+1] ;	// pulse widths of radio inputs
int pwOut[MAX_OUTPUTS+1] ;	// pulse widths for servo outputs

int dutycycle ;				// used to compute PWM duty cycle

union udb_fbts_byte udb_flags ;
union fbts_int flags ;
union dcm_fbts_byte dcm_flags ;
union bfbts_word desired_behavior ;
int current_orientation ;

boolean timer_5_on = 0 ;
boolean needSaveExtendedState = 0 ;
int defaultCorcon = 0 ;

unsigned int uiServosFound = 0;

// Servo data buffers for interface
unsigned int ServoOutDataBuff[8];
unsigned int ServoInDataBuff[8];

unsigned int RxTimeouts = 0;

OP_STATE op_status;


// A SPARE PLACE TO PUT UNUSED INTERUPPT ROUTINES

// Interrupt 0 for Pin RF6, re-used
void __attribute__((__interrupt__,__no_auto_psv__)) _INT0Interrupt(void)
{
	interrupt_save_extended_state ;
	
//	indicate_loading_inter ;
	
	IFS0bits.INT0IF = 0 ; 		// clear the interrupt
	
	interrupt_restore_extended_state ;
	return;
}



/****************************************************************************/
// This is part of the servo and radio interface software
//
// ServoInterface source code
//	http://code.google.com/p/rc-servo-interface
//
// Copyright 2010 ServoInterface Team
// See the AUTHORS.TXT file for a list of authors of ServoInterface.
//
// ServoInterface is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ServoInterface is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License 
// along with ServoInterface.  If not, see <http://www.gnu.org/licenses/>.
//
// Many parts of ServoInterface use either modified or unmodified code
// from the MatrixPilot pilot project.
// The project also contains code for modifying MatrixPilot to operate
// with ServoInterface.
// For details, credits and licenses of MatrixPilot see the AUTHORS.TXT file.
// or see this website: http://code.google.com/p/gentlenav
/****************************************************************************/
